package com.peter.proxy.hkgolden.service;

//public class ContentServiceImpl implements ContentService {
//
//	protected final Logger log = LoggerFactory.getLogger(getClass());
//
//	public Collection<Topic> createTopics() throws Exception {
//		log.debug("createTopics()");
//
//		log.debug("try loading topics from datasource");
//		final TopicDao topicDao = new TopicDao();
//		DataRetrieveStrategy<Topic> dataRetrieveStrategy = new DataRetrieveStrategy<Topic>() {
//			protected Collection<Topic> retrieveFromDao() throws Exception {
//				return topicDao.getTopicList();
//			}
//
//			protected Collection<Topic> retrieveFromHttp() throws Exception {
//				final HttpUrlDownloadStrategy simpleHttpUrlDownload = new HttpUrlDownloadStrategyGAE();
//				simpleHttpUrlDownload
//						.setUrl("http://forum1.hkgolden.com/topics.aspx?type=BW");
//				simpleHttpUrlDownload.setRetry(3);
//				simpleHttpUrlDownload.setTimeout(500);
//				final InputStream response = simpleHttpUrlDownload.call();
//				log.debug("try parsing topics");
//				final Collection<Topic> topics = ContentProvider
//						.createTopics(response);
//				final Date now = ApplicationContext.newDate();
//				for (Topic topic : topics) {
//					topic.setCacheDate(now);
//					topicDao.save(topic);
//				}
//				return topics;
//			}
//		};
//		return dataRetrieveStrategy.call();
//	}
//	//
//	// public Collection<Reply> createReplies(final int id) throws Exception {
//	// log.debug("createReplies()");
//	//
//	// log.debug("try loading replies from datasource");
//	// final ReplyDao replyDao = new ReplyDao();
//	// DataRetrieveStrategy<Reply> dataRetrieveStrategy = new
//	// DataRetrieveStrategy<Reply>() {
//	// protected Collection<Reply> retrieveFromDao() throws Exception {
//	// return replyDao.getReplyList(id);
//	// }
//	//
//	// protected Collection<Reply> retrieveFromHttp() throws Exception {
//	// final HttpUrlDownloadStrategy simpleHttpUrlDownload = new
//	// HttpUrlDownloadStrategyGAE();
//	// simpleHttpUrlDownload
//	// .setUrl("http://forum1.hkgolden.com//view.aspx?message="+id);
//	// simpleHttpUrlDownload.setRetry(3);
//	// simpleHttpUrlDownload.setTimeout(500);
//	// final InputStream response = simpleHttpUrlDownload.call();
//	// log.debug("try parsing replies");
//	// final Collection<Reply> replies =
//	// ContentProvider.createReplies(response);
//	// final Date now = ApplicationContext.newDate();
//	// for (Reply reply : replies) {
//	// // reply.setCacheDate(now);
//	// System.out.println("reply.getId() = " + reply.getId());
//	// replyDao.save(reply);
//	// }
//	// return replies;
//	// }
//	// };
//	// return dataRetrieveStrategy.call();
//	// }
//
// }
